
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.JLabel;
import javax.swing.JOptionPane;


public class Main extends javax.swing.JFrame {
    
    private MaquinaTuring maquina = new MaquinaTuring();
    private ArrayList<JLabel> setas = new ArrayList<>();
    private ArrayList<JLabel> letras = new ArrayList<>();
    private ArrayList<JLabel> lbEstados = new ArrayList<>();
    private int setaAtual = 0, contEstados = 0, estadoAtual = 0;

    public Main() {
        initComponents();
        preencherArray();
        btnEstado.setEnabled(false);
        btnEstadoFim.setEnabled(false);
        btnRemoverEst.setEnabled(false);
        ocularSetas();
        ocultarEstados();
        setas.get(setaAtual).setVisible(true);
        //automato();
        
    }
    
    public void preencherArray(){
        setas.add(lbSeta0);
        setas.add(lbSeta1);
        setas.add(lbSeta2);
        setas.add(lbSeta3);
        setas.add(lbSeta4);
        setas.add(lbSeta5);
        setas.add(lbSeta6);
        setas.add(lbSeta7);
        setas.add(lbSeta8);
        setas.add(lbSeta9);
        setas.add(lbSeta10);
        setas.add(lbSeta11);
        setas.add(lbSeta12); 
        
        letras.add(lbLetra0);
        letras.add(lbLetra1);
        letras.add(lbLetra2);
        letras.add(lbLetra3);
        letras.add(lbLetra4);
        letras.add(lbLetra5);
        letras.add(lbLetra6);
        letras.add(lbLetra7);
        letras.add(lbLetra8);
        letras.add(lbLetra9);
        letras.add(lbLetra10);
        letras.add(lbLetra11);
        letras.add(lbLetra12);
        
        lbEstados.add(lbQ0);
        lbEstados.add(lbQ1);
        lbEstados.add(lbQ2);
        lbEstados.add(lbQ3);
        lbEstados.add(lbQ4);
        lbEstados.add(lbQ5);
        lbEstados.add(lbQ6);
        lbEstados.add(lbQ7);
        lbEstados.add(lbQ8);
        lbEstados.add(lbQ9);
        lbEstados.add(lbQ10);
        lbEstados.add(lbQ11);
        lbEstados.add(lbQ12);
    }
    
    public void ocularSetas(){
        for (int i = 0; i < setas.size(); i++) {
            setas.get(i).setVisible(false);
        }
    }
    
    public void ocultarEstados(){
        for (int i = 0; i < setas.size(); i++) {
            lbEstados.get(i).setVisible(false);
        }
    }
    
    public void adicionarEstados(){
        Estado e = new Estado(contEstados, 'S');
        maquina.addEstado(e);
        lbEstados.get(contEstados).setVisible(true);
        contEstados++;
        
        e = new Estado(contEstados);
        maquina.addEstado(e);
        lbEstados.get(contEstados).setVisible(true);
        contEstados++;
        
        e = new Estado(contEstados);
        maquina.addEstado(e);
        lbEstados.get(contEstados).setVisible(true);
        contEstados++;
        
        e = new Estado(contEstados);
        maquina.addEstado(e);
        lbEstados.get(contEstados).setVisible(true);
        contEstados++;
        
        e = new Estado(contEstados);
        maquina.addEstado(e);
        lbEstados.get(contEstados).setVisible(true);
        contEstados++;
        
        e = new Estado(contEstados, 'F');
        maquina.addEstado(e);
        lbEstados.get(contEstados).setVisible(true);
        contEstados++;
    }
    
    public void automato(){
        /**Estado e =  new Estado(0);
        maquina.addEstado(e);
        e =  new Estado(1);
        maquina.addEstado(e);
        e = new Estado(2);
        maquina.addEstado(e);
        e =  new Estado(3);
        maquina.addEstado(e);
        e =  new Estado(4);
        maquina.addEstado(e);
        e =  new Estado(5, 'F');
        maquina.addEstado(e);**/
        adicionarEstados();
        
        Transicoes t = new Transicoes(1, 'a', 'A', 'D');
        maquina.addTransition(0, t);
        t = new Transicoes(0, 'A', 'A', 'D');
        maquina.addTransition(0, t);
        t = new Transicoes(0, 'B', 'B', 'D');
        maquina.addTransition(0, t);
        
        t = new Transicoes(1, 'a', 'a', 'D');
        maquina.addTransition(1, t);
        t = new Transicoes(1, 'B', 'B', 'D');
        maquina.addTransition(1, t);
        t = new Transicoes(3, 'b', 'B', 'E');
        maquina.addTransition(1, t);
        
        t = new Transicoes(3, 'a', 'a', 'E');
        maquina.addTransition(3, t);
        t = new Transicoes(3, 'A', 'A', 'E');
        maquina.addTransition(3, t);
        t = new Transicoes(3, 'b', 'b', 'E');
        maquina.addTransition(3, t);
        t = new Transicoes(3, 'B', 'B', 'E');
        maquina.addTransition(3, t);
        t = new Transicoes(0, '$', '$', 'D');
        maquina.addTransition(3, t);
        
        t = new Transicoes(2, 'b', 'B', 'D');
        maquina.addTransition(0, t);
        t = new Transicoes(2, 'A', 'A', 'D');
        maquina.addTransition(2, t);
        t = new Transicoes(2, 'b', 'b', 'D');
        maquina.addTransition(2, t);
        t = new Transicoes(4, 'a', 'A', 'E');
        maquina.addTransition(2, t);
        
        t = new Transicoes(4, 'a', 'a', 'E');
        maquina.addTransition(4, t);
        t = new Transicoes(4, 'A', 'A', 'E');
        maquina.addTransition(4, t);
        t = new Transicoes(4, 'b', 'b', 'E');
        maquina.addTransition(4, t);
        t = new Transicoes(4, 'B', 'B', 'E');
        maquina.addTransition(4, t);
        t = new Transicoes(0, '$', '$', 'D');
        maquina.addTransition(4, t);
        
        t = new Transicoes(5, '$', '$', 'D');
        maquina.addTransition(0, t);
    }
    
    public void zerarFita(){
        btnNext.setEnabled(true);
        ocularSetas();
        setaAtual = 0;
        contEstados = 0;
        estadoAtual = 0;
        setas.get(setaAtual).setVisible(true);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane1 = new javax.swing.JDesktopPane();
        lbTitulo = new javax.swing.JLabel();
        lbEstado = new javax.swing.JLabel();
        btnEstadoInic = new javax.swing.JButton();
        btnEstadoFim = new javax.swing.JButton();
        btnEstado = new javax.swing.JButton();
        btnRemoverEst = new javax.swing.JButton();
        lbTransicoes = new javax.swing.JLabel();
        btnAddTrans = new javax.swing.JButton();
        btnRemoverTrans = new javax.swing.JButton();
        lbPalavra = new javax.swing.JLabel();
        lbLetra0 = new javax.swing.JLabel();
        lbLetra1 = new javax.swing.JLabel();
        lbLetra2 = new javax.swing.JLabel();
        lbLetra3 = new javax.swing.JLabel();
        lbLetra4 = new javax.swing.JLabel();
        lbLetra5 = new javax.swing.JLabel();
        lbLetra6 = new javax.swing.JLabel();
        lbLetra7 = new javax.swing.JLabel();
        lbLetra9 = new javax.swing.JLabel();
        lbLetra10 = new javax.swing.JLabel();
        lbLetra11 = new javax.swing.JLabel();
        lbLetra12 = new javax.swing.JLabel();
        lbLetra8 = new javax.swing.JLabel();
        lbJanela0 = new javax.swing.JLabel();
        lbJanela1 = new javax.swing.JLabel();
        lbJanela3 = new javax.swing.JLabel();
        lbJanela2 = new javax.swing.JLabel();
        lbJanela4 = new javax.swing.JLabel();
        lbJanela5 = new javax.swing.JLabel();
        lbJanela6 = new javax.swing.JLabel();
        lbJanela7 = new javax.swing.JLabel();
        lbJanela8 = new javax.swing.JLabel();
        lbJanela9 = new javax.swing.JLabel();
        lbJanela10 = new javax.swing.JLabel();
        lbJanela11 = new javax.swing.JLabel();
        lbJanela12 = new javax.swing.JLabel();
        lbSeta0 = new javax.swing.JLabel();
        lbSeta2 = new javax.swing.JLabel();
        lbSeta1 = new javax.swing.JLabel();
        lbSeta3 = new javax.swing.JLabel();
        lbSeta4 = new javax.swing.JLabel();
        lbSeta5 = new javax.swing.JLabel();
        lbSeta6 = new javax.swing.JLabel();
        lbSeta7 = new javax.swing.JLabel();
        lbSeta8 = new javax.swing.JLabel();
        lbSeta9 = new javax.swing.JLabel();
        lbSeta10 = new javax.swing.JLabel();
        lbSeta11 = new javax.swing.JLabel();
        lbSeta12 = new javax.swing.JLabel();
        btnNext = new javax.swing.JButton();
        btnAddPalavra = new javax.swing.JButton();
        lbQ0 = new javax.swing.JLabel();
        lbQ1 = new javax.swing.JLabel();
        lbQ2 = new javax.swing.JLabel();
        lbQ3 = new javax.swing.JLabel();
        lbQ4 = new javax.swing.JLabel();
        lbQ5 = new javax.swing.JLabel();
        lbQ6 = new javax.swing.JLabel();
        lbQ7 = new javax.swing.JLabel();
        lbQ8 = new javax.swing.JLabel();
        lbQ9 = new javax.swing.JLabel();
        lbQ10 = new javax.swing.JLabel();
        lbQ11 = new javax.swing.JLabel();
        lbQ12 = new javax.swing.JLabel();
        lbEstadoAtual = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jDesktopPane1.setBackground(new java.awt.Color(240, 240, 240));

        lbTitulo.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbTitulo.setText("SIMULADOR - MAQUINA DE TURING");
        jDesktopPane1.add(lbTitulo);
        lbTitulo.setBounds(10, 10, 780, 30);

        lbEstado.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbEstado.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbEstado.setText("ESTADOS");
        jDesktopPane1.add(lbEstado);
        lbEstado.setBounds(10, 60, 390, 22);

        btnEstadoInic.setText("Estado Inicial");
        btnEstadoInic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEstadoInicActionPerformed(evt);
            }
        });
        jDesktopPane1.add(btnEstadoInic);
        btnEstadoInic.setBounds(20, 90, 120, 27);

        btnEstadoFim.setText("Estado Final");
        btnEstadoFim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEstadoFimActionPerformed(evt);
            }
        });
        jDesktopPane1.add(btnEstadoFim);
        btnEstadoFim.setBounds(140, 90, 110, 27);

        btnEstado.setText("Estado");
        btnEstado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEstadoActionPerformed(evt);
            }
        });
        jDesktopPane1.add(btnEstado);
        btnEstado.setBounds(250, 90, 100, 27);

        btnRemoverEst.setText("Remover");
        btnRemoverEst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverEstActionPerformed(evt);
            }
        });
        jDesktopPane1.add(btnRemoverEst);
        btnRemoverEst.setBounds(350, 90, 100, 27);

        lbTransicoes.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbTransicoes.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbTransicoes.setText("TRANSIÇÕES");
        jDesktopPane1.add(lbTransicoes);
        lbTransicoes.setBounds(610, 60, 180, 22);

        btnAddTrans.setText("Adicionar");
        btnAddTrans.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddTransActionPerformed(evt);
            }
        });
        jDesktopPane1.add(btnAddTrans);
        btnAddTrans.setBounds(700, 90, 90, 27);

        btnRemoverTrans.setText("Remover");
        btnRemoverTrans.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverTransActionPerformed(evt);
            }
        });
        jDesktopPane1.add(btnRemoverTrans);
        btnRemoverTrans.setBounds(610, 90, 90, 27);

        lbPalavra.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbPalavra.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbPalavra.setText("FITA");
        jDesktopPane1.add(lbPalavra);
        lbPalavra.setBounds(80, 170, 590, 20);

        lbLetra0.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra0.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra0);
        lbLetra0.setBounds(20, 210, 30, 20);

        lbLetra1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra1);
        lbLetra1.setBounds(80, 210, 30, 20);

        lbLetra2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra2);
        lbLetra2.setBounds(140, 210, 30, 20);

        lbLetra3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra3);
        lbLetra3.setBounds(200, 210, 30, 20);

        lbLetra4.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra4);
        lbLetra4.setBounds(260, 210, 30, 20);

        lbLetra5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra5);
        lbLetra5.setBounds(320, 210, 30, 20);

        lbLetra6.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra6);
        lbLetra6.setBounds(380, 210, 30, 20);

        lbLetra7.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra7);
        lbLetra7.setBounds(440, 210, 30, 20);

        lbLetra9.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra9);
        lbLetra9.setBounds(560, 210, 30, 20);

        lbLetra10.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra10);
        lbLetra10.setBounds(620, 210, 30, 20);

        lbLetra11.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra11);
        lbLetra11.setBounds(680, 210, 30, 20);

        lbLetra12.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra12);
        lbLetra12.setBounds(740, 210, 30, 20);

        lbLetra8.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbLetra8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jDesktopPane1.add(lbLetra8);
        lbLetra8.setBounds(500, 210, 30, 20);

        lbJanela0.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela0);
        lbJanela0.setBounds(10, 200, 50, 42);

        lbJanela1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela1);
        lbJanela1.setBounds(70, 200, 50, 42);

        lbJanela3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela3);
        lbJanela3.setBounds(190, 200, 50, 42);

        lbJanela2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela2);
        lbJanela2.setBounds(130, 200, 50, 40);

        lbJanela4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela4);
        lbJanela4.setBounds(250, 200, 50, 42);

        lbJanela5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela5);
        lbJanela5.setBounds(310, 200, 50, 42);

        lbJanela6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela6);
        lbJanela6.setBounds(370, 200, 50, 42);

        lbJanela7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela7);
        lbJanela7.setBounds(430, 200, 50, 40);

        lbJanela8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela8);
        lbJanela8.setBounds(490, 200, 50, 42);

        lbJanela9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela9);
        lbJanela9.setBounds(550, 200, 50, 42);

        lbJanela10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela10);
        lbJanela10.setBounds(610, 200, 50, 40);

        lbJanela11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela11);
        lbJanela11.setBounds(670, 200, 50, 42);

        lbJanela12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/celula.png"))); // NOI18N
        jDesktopPane1.add(lbJanela12);
        lbJanela12.setBounds(730, 200, 50, 42);

        lbSeta0.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta0);
        lbSeta0.setBounds(10, 250, 50, 50);

        lbSeta2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta2);
        lbSeta2.setBounds(130, 250, 50, 50);

        lbSeta1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta1);
        lbSeta1.setBounds(70, 250, 50, 50);

        lbSeta3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta3);
        lbSeta3.setBounds(190, 250, 50, 48);

        lbSeta4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta4);
        lbSeta4.setBounds(250, 250, 50, 48);

        lbSeta5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta5);
        lbSeta5.setBounds(310, 250, 50, 50);

        lbSeta6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta6);
        lbSeta6.setBounds(370, 250, 50, 50);

        lbSeta7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta7);
        lbSeta7.setBounds(430, 250, 50, 50);

        lbSeta8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta8);
        lbSeta8.setBounds(490, 250, 50, 50);

        lbSeta9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta9);
        lbSeta9.setBounds(550, 250, 50, 50);

        lbSeta10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta10);
        lbSeta10.setBounds(610, 250, 50, 50);

        lbSeta11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta11);
        lbSeta11.setBounds(670, 250, 50, 50);

        lbSeta12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/seta_cima.png"))); // NOI18N
        jDesktopPane1.add(lbSeta12);
        lbSeta12.setBounds(730, 250, 50, 50);

        btnNext.setText("Proximo");
        btnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextActionPerformed(evt);
            }
        });
        jDesktopPane1.add(btnNext);
        btnNext.setBounds(340, 390, 120, 27);

        btnAddPalavra.setText("Adicionar Palavra");
        btnAddPalavra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddPalavraActionPerformed(evt);
            }
        });
        jDesktopPane1.add(btnAddPalavra);
        btnAddPalavra.setBounds(613, 140, 170, 27);

        lbQ0.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ0.setForeground(new java.awt.Color(255, 255, 255));
        lbQ0.setText("Q0");
        lbQ0.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ0MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ0);
        lbQ0.setBounds(20, 320, 40, 40);

        lbQ1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ1.setForeground(new java.awt.Color(255, 255, 255));
        lbQ1.setText("Q1");
        lbQ1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ1MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ1);
        lbQ1.setBounds(80, 320, 40, 40);

        lbQ2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ2.setForeground(new java.awt.Color(255, 255, 255));
        lbQ2.setText("Q2");
        lbQ2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ2MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ2);
        lbQ2.setBounds(140, 320, 40, 40);

        lbQ3.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ3.setForeground(new java.awt.Color(255, 255, 255));
        lbQ3.setText("Q3");
        lbQ3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ3MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ3);
        lbQ3.setBounds(200, 320, 40, 40);

        lbQ4.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ4.setForeground(new java.awt.Color(255, 255, 255));
        lbQ4.setText("Q4");
        lbQ4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ4MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ4);
        lbQ4.setBounds(260, 320, 40, 40);

        lbQ5.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ5.setForeground(new java.awt.Color(255, 255, 255));
        lbQ5.setText("Q5");
        lbQ5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ5MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ5);
        lbQ5.setBounds(320, 320, 40, 40);

        lbQ6.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ6.setForeground(new java.awt.Color(255, 255, 255));
        lbQ6.setText("Q6");
        lbQ6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ6MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ6);
        lbQ6.setBounds(380, 320, 40, 40);

        lbQ7.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ7.setForeground(new java.awt.Color(255, 255, 255));
        lbQ7.setText("Q7");
        lbQ7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ7MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ7);
        lbQ7.setBounds(440, 320, 40, 40);

        lbQ8.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ8.setForeground(new java.awt.Color(255, 255, 255));
        lbQ8.setText("Q8");
        lbQ8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ8MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ8);
        lbQ8.setBounds(500, 320, 40, 40);

        lbQ9.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ9.setForeground(new java.awt.Color(255, 255, 255));
        lbQ9.setText("Q9");
        lbQ9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ9MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ9);
        lbQ9.setBounds(560, 320, 40, 40);

        lbQ10.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ10.setForeground(new java.awt.Color(255, 255, 255));
        lbQ10.setText("Q10");
        lbQ10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ10MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ10);
        lbQ10.setBounds(610, 320, 60, 40);

        lbQ11.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ11.setForeground(new java.awt.Color(255, 255, 255));
        lbQ11.setText("Q11");
        lbQ11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ11MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ11);
        lbQ11.setBounds(670, 320, 54, 40);

        lbQ12.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbQ12.setForeground(new java.awt.Color(255, 255, 255));
        lbQ12.setText("Q12");
        lbQ12.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbQ12MouseClicked(evt);
            }
        });
        jDesktopPane1.add(lbQ12);
        lbQ12.setBounds(730, 320, 60, 40);

        lbEstadoAtual.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbEstadoAtual.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbEstadoAtual.setText("Estado Atual");
        jDesktopPane1.add(lbEstadoAtual);
        lbEstadoAtual.setBounds(20, 300, 760, 30);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 807, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnEstadoInicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEstadoInicActionPerformed
        Estado e = new Estado(contEstados, 'S');
        maquina.addEstado(e);
        btnEstado.setEnabled(true);
        btnEstadoFim.setEnabled(true);
        btnRemoverEst.setEnabled(true);
        btnEstadoInic.setEnabled(false);
        lbEstados.get(contEstados).setVisible(true);
        contEstados++;
        JOptionPane.showMessageDialog(rootPane, "Estado Inicial q0 Adicionado");
    }//GEN-LAST:event_btnEstadoInicActionPerformed

    private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextActionPerformed
        setas.get(setaAtual).setVisible(false);
        lbEstados.get(estadoAtual).setForeground(Color.WHITE);
        if(!maquina.verificar()){
            letras.get(maquina.idFitaAnt).setText(""+maquina.estados[maquina.estadoAnt].transitions.getTransition(maquina.aux).getSimbGravar());
            setaAtual = maquina.idFita;
            setas.get(setaAtual).setVisible(true);
            estadoAtual = maquina.estadoAtual;
            lbEstados.get(estadoAtual).setForeground(Color.BLACK);
        } else {
            estadoAtual = maquina.estadoAtual;
            lbEstados.get(estadoAtual).setForeground(Color.BLACK);
            btnNext.setEnabled(false);
            //JOptionPane.showMessageDialog(rootPane, "Palavra Aceita");
        }   
    }//GEN-LAST:event_btnNextActionPerformed

    private void btnAddPalavraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddPalavraActionPerformed
        estadoAtual = maquina.estadoAtual;
        lbEstados.get(estadoAtual).setForeground(Color.WHITE);
        zerarFita();
        String palavra = JOptionPane.showInputDialog("Digite a Palavra a ser lida");
        maquina.addPalavraFita(palavra);
        for (int i = 0; i < letras.size(); i++) {
            letras.get(i).setText(""+maquina.fita[i]);
        }
        setas.get(setaAtual).setVisible(false);
        setaAtual = maquina.idFita;
        setas.get(setaAtual).setVisible(true);
        lbEstados.get(estadoAtual).setForeground(Color.black);
    }//GEN-LAST:event_btnAddPalavraActionPerformed

    private void btnEstadoFimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEstadoFimActionPerformed
        Estado e = new Estado(contEstados, 'F');
        maquina.addEstado(e);
        lbEstados.get(contEstados).setVisible(true);
        contEstados++;
        JOptionPane.showMessageDialog(rootPane, "Estado Final "+e.getNome()+" Adicionado");
    }//GEN-LAST:event_btnEstadoFimActionPerformed

    private void btnEstadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEstadoActionPerformed
        Estado e = new Estado(contEstados);
        maquina.addEstado(e);
        lbEstados.get(contEstados).setVisible(true);
        contEstados++;
        JOptionPane.showMessageDialog(rootPane, "Estado "+e.getNome()+" Adicionado");
    }//GEN-LAST:event_btnEstadoActionPerformed

    private void btnRemoverEstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverEstActionPerformed
        int i = Integer.parseInt(JOptionPane.showInputDialog("Digite qual estado deseja remover"));
        if(maquina.removerEstado(i)){
            JOptionPane.showMessageDialog(rootPane, "Estado Removido");
            lbEstados.get(i).setVisible(false);
            //contEstados--;
        } else {
            JOptionPane.showMessageDialog(rootPane, "Estado não existe");
        }
    }//GEN-LAST:event_btnRemoverEstActionPerformed

    private void btnRemoverTransActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverTransActionPerformed
        int idEstado = Integer.parseInt(JOptionPane.showInputDialog("Digite o estado que deseja remover a transição"));
        maquina.transicoesEstado(idEstado);
        int idTrans = Integer.parseInt(JOptionPane.showInputDialog("Digite a transição que deseja remover"));
        maquina.removerTransition(idEstado, idTrans);
        maquina.transicoesEstado(idEstado);
    }//GEN-LAST:event_btnRemoverTransActionPerformed

    private void btnAddTransActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddTransActionPerformed
        int idEstado = Integer.parseInt(JOptionPane.showInputDialog("Digite o Estado de Origem"));
        int destino = Integer.parseInt(JOptionPane.showInputDialog("Digite o estado de Destino"));
        char leitura = JOptionPane.showInputDialog("Digite o Simbolo de Leitura").charAt(0);
        char gravar = JOptionPane.showInputDialog("Digite o Simbolo de Gravação").charAt(0);
        char mov = JOptionPane.showInputDialog("Digite o Movimento da Fita").charAt(0);
        Transicoes t = new Transicoes(destino, leitura, gravar, mov);
        maquina.addTransition(idEstado, t);
    }//GEN-LAST:event_btnAddTransActionPerformed

    private void lbQ1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ1MouseClicked
        maquina.transicoesEstado(1);
    }//GEN-LAST:event_lbQ1MouseClicked

    private void lbQ2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ2MouseClicked
        maquina.transicoesEstado(2);
    }//GEN-LAST:event_lbQ2MouseClicked

    private void lbQ0MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ0MouseClicked
        maquina.transicoesEstado(0);
    }//GEN-LAST:event_lbQ0MouseClicked

    private void lbQ3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ3MouseClicked
        maquina.transicoesEstado(3);
    }//GEN-LAST:event_lbQ3MouseClicked

    private void lbQ4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ4MouseClicked
        maquina.transicoesEstado(4);
    }//GEN-LAST:event_lbQ4MouseClicked

    private void lbQ5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ5MouseClicked
        maquina.transicoesEstado(5);
    }//GEN-LAST:event_lbQ5MouseClicked

    private void lbQ6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ6MouseClicked
        maquina.transicoesEstado(6);
    }//GEN-LAST:event_lbQ6MouseClicked

    private void lbQ7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ7MouseClicked
        maquina.transicoesEstado(7);
    }//GEN-LAST:event_lbQ7MouseClicked

    private void lbQ8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ8MouseClicked
        maquina.transicoesEstado(8);
    }//GEN-LAST:event_lbQ8MouseClicked

    private void lbQ9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ9MouseClicked
        maquina.transicoesEstado(9);
    }//GEN-LAST:event_lbQ9MouseClicked

    private void lbQ10MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ10MouseClicked
        maquina.transicoesEstado(10);
    }//GEN-LAST:event_lbQ10MouseClicked

    private void lbQ11MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ11MouseClicked
        maquina.transicoesEstado(11);
    }//GEN-LAST:event_lbQ11MouseClicked

    private void lbQ12MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbQ12MouseClicked
        maquina.transicoesEstado(12);
    }//GEN-LAST:event_lbQ12MouseClicked


    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddPalavra;
    private javax.swing.JButton btnAddTrans;
    private javax.swing.JButton btnEstado;
    private javax.swing.JButton btnEstadoFim;
    private javax.swing.JButton btnEstadoInic;
    private javax.swing.JButton btnNext;
    private javax.swing.JButton btnRemoverEst;
    private javax.swing.JButton btnRemoverTrans;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel lbEstado;
    private javax.swing.JLabel lbEstadoAtual;
    private javax.swing.JLabel lbJanela0;
    private javax.swing.JLabel lbJanela1;
    private javax.swing.JLabel lbJanela10;
    private javax.swing.JLabel lbJanela11;
    private javax.swing.JLabel lbJanela12;
    private javax.swing.JLabel lbJanela2;
    private javax.swing.JLabel lbJanela3;
    private javax.swing.JLabel lbJanela4;
    private javax.swing.JLabel lbJanela5;
    private javax.swing.JLabel lbJanela6;
    private javax.swing.JLabel lbJanela7;
    private javax.swing.JLabel lbJanela8;
    private javax.swing.JLabel lbJanela9;
    private javax.swing.JLabel lbLetra0;
    private javax.swing.JLabel lbLetra1;
    private javax.swing.JLabel lbLetra10;
    private javax.swing.JLabel lbLetra11;
    private javax.swing.JLabel lbLetra12;
    private javax.swing.JLabel lbLetra2;
    private javax.swing.JLabel lbLetra3;
    private javax.swing.JLabel lbLetra4;
    private javax.swing.JLabel lbLetra5;
    private javax.swing.JLabel lbLetra6;
    private javax.swing.JLabel lbLetra7;
    private javax.swing.JLabel lbLetra8;
    private javax.swing.JLabel lbLetra9;
    private javax.swing.JLabel lbPalavra;
    private javax.swing.JLabel lbQ0;
    private javax.swing.JLabel lbQ1;
    private javax.swing.JLabel lbQ10;
    private javax.swing.JLabel lbQ11;
    private javax.swing.JLabel lbQ12;
    private javax.swing.JLabel lbQ2;
    private javax.swing.JLabel lbQ3;
    private javax.swing.JLabel lbQ4;
    private javax.swing.JLabel lbQ5;
    private javax.swing.JLabel lbQ6;
    private javax.swing.JLabel lbQ7;
    private javax.swing.JLabel lbQ8;
    private javax.swing.JLabel lbQ9;
    private javax.swing.JLabel lbSeta0;
    private javax.swing.JLabel lbSeta1;
    private javax.swing.JLabel lbSeta10;
    private javax.swing.JLabel lbSeta11;
    private javax.swing.JLabel lbSeta12;
    private javax.swing.JLabel lbSeta2;
    private javax.swing.JLabel lbSeta3;
    private javax.swing.JLabel lbSeta4;
    private javax.swing.JLabel lbSeta5;
    private javax.swing.JLabel lbSeta6;
    private javax.swing.JLabel lbSeta7;
    private javax.swing.JLabel lbSeta8;
    private javax.swing.JLabel lbSeta9;
    private javax.swing.JLabel lbTitulo;
    private javax.swing.JLabel lbTransicoes;
    // End of variables declaration//GEN-END:variables
}
